// SetInfoDialog.cpp : implementation file
//

#include "../stdafx.h"
#include "../Reflectometry.h"
#include "SetInfoDialog.h"
#include "SolarPositionDialog.h"
#include "afxdialogex.h"

#include "../MainFrm.h"
#include "../ReflectometryDoc.h"
#include "../sky/Sun.h"
#include "../base/Base.h"


// CSetInfoDialog dialog

IMPLEMENT_DYNAMIC(CSetInfoDialog, CDialogEx)

CSetInfoDialog::CSetInfoDialog(CWnd* pParent /*=NULL*/)
	: CDialogEx(CSetInfoDialog::IDD, pParent)
	, m_hour(0)
	, m_minute(0)
	, m_timeZone(8)
	, m_latitude(40)
	, m_longitude(116)
{

}

CSetInfoDialog::~CSetInfoDialog()
{
}

void CSetInfoDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT_HOUR, m_hour);
	DDX_Text(pDX, IDC_EDIT_MINUTE, m_minute);
	DDX_Text(pDX, IDC_EDIT_TIMEZONE, m_timeZone);
	DDX_Text(pDX, IDC_EDIT_LATITUDE, m_latitude);
	DDX_Text(pDX, IDC_EDIT6_LONGITUDE, m_longitude);
	DDX_Control(pDX, IDC_DATETIMEPICKER, m_dateTimePicker);
}


BEGIN_MESSAGE_MAP(CSetInfoDialog, CDialogEx)
	ON_BN_CLICKED(IDOK, &CSetInfoDialog::OnBnClickedOk)
END_MESSAGE_MAP()


// CSetInfoDialog message handlers


void CSetInfoDialog::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	
	UpdateData(TRUE);
	
	CMainFrame *pMainFrame = (CMainFrame *)AfxGetMainWnd();
	CReflectometryDoc *pDoc = (CReflectometryDoc *)(pMainFrame->GetActiveDocument());
	CSun *pSun = pDoc->GetClearSky()->GetSun();

	CGeoInfo geoInfo;
	geoInfo.m_latitude = m_latitude;
	geoInfo.m_longitude = m_longitude;
	pSun->SetGeoInfo(geoInfo);

	CTime time;
	m_dateTimePicker.GetTime(time);

	CDate date;
	date.m_year = time.GetYear();
	date.m_month = time.GetMonth();
	date.m_day = time.GetDay();
	date.m_hour = m_hour;
	date.m_minute = m_minute;
	date.m_timeZone = m_timeZone;
	pSun->SetDate(date);

	UpdateData(FALSE);

	CSolarPositionDialog solarPositionDlg;
	solarPositionDlg.DoModal();
	CDialogEx::OnOK();
}
